<?php

namespace app\common\service;


class HostManager extends Base 

{
    /**
     * @name 列表
     * @param $params
     * @param $limit
     * @return array
     * @author wx
     * @date 2019/10/25 14:01
     */
    function list($params, $limit)
    {
        $db = db('host_manager');

        if(isset($params['name']) && !empty($params['name'])){
            $db->where('hma.name', 'like','%'.$params['name'].'%');
        }
        if(isset($params['gender']) && !empty($params['gender'])){
            $db->where('gender', $params['gender']);
        }
        if(isset($params['ministry_id']) && !empty($params['ministry_id'])){
            $db->where('ministry_id', $params['ministry_id']);
        }
        if(isset($params['phone']) && !empty($params['phone'])){
            $db->where('phone', 'like','%'.$params['phone'].'%');
        }

        return $db->alias('hma')
            ->join('host_ministry hmi','hma.ministry_id = hmi.id')
            ->field('hma.id, hma.name, hma.gender, hma.ministry_id, hma.phone, hmi.name as ministry')
            ->order('hma.id desc')->paginate($limit)->toArray();
    }

    /**
     * @name 添加
     * @param $addData
     * @return int|string
     * @author wx
     * @date 2019/10/25 14:03
     */
    function add($addData)
    {
        return db('host_manager')->insert($addData);
    }

    /**
     * @name 查询数据
     * @param $condition
     * @return array|null|\PDOStatement|string|\think\Model
     * @author wx
     * @date time
     */
    function findData($condition)
    {
        return db('host_manager')->where($condition)->find();
    }

    /**
     * @name: 管理员展示
     * @Param: managerId_a  管理员id 数组
     * @Description: 
     * @Author: foo
     * @Date: 2019-03-27 10:07:26
     */
    function showManager ($managerId_a = [], $field = '', $index ='')
    {
        $server = db('HostManager');

        empty($managerId_a) ? : $server->whereIn('id', $managerId_a);

        empty($field) ? : $server->field($field);

        $managerData = empty($index) ? $server->select() : $server->column($field, $index);

        return $managerData;
    }

    /**
     * @name 修改
     * @param $condition
     * @param $updateData
     * @return int|string
     * @author wx
     * @date time
     */
    function modify($condition, $updateData)
    {
        return db('host_manager')->where($condition)->update($updateData);
    }

    /**
     * @name 删除
     * @param $condition
     * @return int
     * @author wx
     * @date 2019/10/25 14:05
     */
    function del($condition)
    {
        return db('host_manager')->where($condition)->delete();
    }
}